package cn.zzqayy.elasticsearch.simple.example.controller;

import cn.zzqayy.elasticsearch.simple.example.entity.elasticsearch.WorkType;
import cn.zzqayy.elasticsearch.simple.example.repository.EsWorkTypeRepository;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 获取一些基本信息
 * @author zzqayy
 * @date 2021/2/25
 */
@RestController
public class TestController {

    @Resource
    private EsWorkTypeRepository esWorkTypeRepository;

    @RequestMapping("/test")
    public Iterable<WorkType> test() {
        Iterable<WorkType> all = esWorkTypeRepository.findAll(Sort.by(Sort.Direction.DESC, "id"));
        return all;
    }

    @RequestMapping("/test/save")
    public boolean save() {
        for (int i = 1; i <= 20; i++) {
            WorkType workType = new WorkType();
            workType.setId(i);
            workType.setWorkTypeName("测试" + i);
            esWorkTypeRepository.save(workType);
        }
        return true;
    }



}
